package com.nbsaas.boot.project.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.code.annotation.data.Dict;
import com.nbsaas.boot.code.annotation.data.DictItem;
import com.nbsaas.boot.jpa.data.entity.AbstractEntity;
import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.project.api.domain.enums.ProjectState;
import com.nbsaas.boot.rest.enums.StoreState;
import com.nbsaas.boot.rest.filter.Operator;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Comment;

import java.math.BigDecimal;
import java.util.Date;

@EqualsAndHashCode(callSuper = true)
@Comment("项目")
@FormAnnotation(model = "项目")
@Data
@Entity
@Table(name = "nb_project")
public class Project extends AbstractEntity {


    @FieldConvert
    @FieldName
    @ManyToOne(fetch = FetchType.LAZY)
    private User creator;


    @SearchItem(name = "state", key = "state", label = "项目状态", operator = Operator.eq, type = InputType.select, classType = Integer.class)
    @Comment("项目状态")
    @Dict(
            items = {
                    @DictItem(label = "待启动", value = 1),
                    @DictItem(label = "进行中", value = 2),
                    @DictItem(label = "暂停", value = 3),
                    @DictItem(label = "已结束", value = 4),
                    @DictItem(label = "取消", value = 5),
                    @DictItem(label = "归档", value = 6),
                    @DictItem(label = "删除", value = 7),
                    @DictItem(label = "已完成", value = 7)

            }
    )
    private Integer state;

    //进度
    @Comment("进度")
    @FormField(title = "进度", sortNum = "1", grid = true, ignore = true)
    private Integer progress;


    @SearchItem(name = "stopState", key = "stopState", label = "项目停止状态", operator = Operator.eq, type = InputType.select, classType = Integer.class)
    @Comment("项目停止状态")
    @Dict(
            items = {
                    @DictItem(label = "未终止", value = 1),
                    @DictItem(label = "已终止", value = 2),
            }
    )
    private Integer stopState;


    /**
     * 项目负责人
     */
    @FieldConvert
    @SearchItem(name = "charger", key = "charger.name", label = "项目负责人")
    @FormField(title = "项目负责人", sortNum = "2", grid = true, col = 12, ignore = true)
    @ManyToOne(fetch = FetchType.LAZY)
    private User charger;


    @SearchItem(name = "catalog", key = "catalog.id", label = "项目分类", operator = Operator.eq, type = InputType.select, classType = Long.class)
    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private ProjectCatalog catalog;

    /**
     * 项目名称
     */
    @SearchItem(name = "name", key = "name", label = "项目名称")
    @FormField(title = "项目名称", sortNum = "1", grid = true, required = true, width = "200")
    @Column(length = 30)
    private String name;


    @FormField(title = "合同金额", sortNum = "1", grid = true)
    private BigDecimal money;

    @FormField(title = "回款金额", sortNum = "1", grid = true, ignore = true)
    private BigDecimal backMoney;


    /**
     * 存储状态
     */
    private StoreState storeState;

    /**
     * 开始日期
     */
    @FormField(title = "开始日期", type = InputType.date, sortNum = "4", width = "1600", grid = true)
    private Date beginDate;

    /**
     * 截至日期
     */
    @FormField(title = "截至日期", type = InputType.date, sortNum = "5", width = "160")
    private Date deadline;

    @FormField(title = "任务个数", sortNum = "3", grid = true, ignore = true)
    private Long totalNum;

    @FormField(title = "项目用时", sortNum = "3", grid = true, ignore = true)
    private Long usedTime;


    private ProjectState projectState;

    private String address;

    /**
     * 项目颜色
     */
    @Column(length = 10)
    private String color;

    private Float lat;

    private Float lng;

}
